package com.xszx.service.impl;

import com.xszx.entity.*;
import com.xszx.mapper.AdminMapper;
import com.xszx.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author:瓦达西瓦
 * @date:2024/10/31
 */
@Service
public class AdminServiceImpl  implements AdminService {

    private AdminMapper adminMapper;
    @Autowired
    public void setAdminMapper(AdminMapper adminMapper) {
        this.adminMapper = adminMapper;
    }

    @Override
    public List<Goods> getGoodList() {
        System.out.println("进入service");
        List<Goods> list=adminMapper.getGoodList();
        return list;
    }

    @Override
    public Integer delGood(int gid) {
      Integer i= adminMapper.delGood(gid);
        return i;
    }

    @Override
    public List<Goods> getGoodMoHuList(Goods goods,Double minprice,Double maxprice) {
        System.out.println("service层");
        List<Goods> list=adminMapper.getGoodMoHuList(goods,minprice,maxprice);
        return list;
    }

    @Override
    public Integer checkGid(int gid) {
       Integer t= adminMapper.checkGid(gid);
        return t;
    }

    @Override
    public List<Order> getOrderList() {
        List<Order> list=adminMapper.getOrderList();
        return list;
    }


    public List<Order> getOrderMoHuList(Order order) {
        List<Order> list=adminMapper.getOrderMoHuList(order);
        return list;

    }

    @Override
    public Integer rtMoney(Order order) {
       Integer i= adminMapper.rtMoney(order);
        return i;
    }

    @Override
    public Integer IfrtMoney(Integer oid, Integer rtmoney) {
        String  rtstatus="";
        if(rtmoney==1){
        rtstatus="退款成功";

        }else{
           rtstatus="退款失败";
        }
        Integer i= adminMapper.IfrtMoney(oid,rtstatus);
        return i;
    }

    @Override
    public Integer checkTime(String oid) {
      Integer i= adminMapper.checkTime(oid);
        return i;
    }

    @Override
    public List<Comments> getMommentList() {
        List<Comments> list=adminMapper.getMommentList();
        return list;
    }

    @Override
    public Integer delComment(int cid) {
      Integer i= adminMapper.delComment(cid);
        return i;
    }

    @Override
    public Integer checkGood(Integer gid) {
       Integer i= adminMapper.checkGood(gid);
        return i;
    }

    @Override
    public Integer checkGoodResult(Goods goods, Integer p) {
        String status="";
        if(p==1){
           status="审核通过";
        }else{
          status="审核失败";
        }
      Integer i=adminMapper.checkGoodResult(goods,status);
        return i;
    }

    @Override
    public List<Goods> getcheckGood() {
        List<Goods> list=adminMapper.getcheckGood();
        return list;
    }

    @Override
    public List<Order> getrtMoney() {
        List<Order> list=  adminMapper.getrtMoney();
        return list;
    }

    @Override
    public List<Comments> getComment(Integer gid) {
        List<Comments> list=  adminMapper.getComment(gid);
        return list;
    }

    @Override
    public Integer goComment(Comments comment) {
      Integer i=adminMapper.goComment(comment);
        return i;
    }

    @Override
    public Integer checkIfrtmoney(Order order) {
      Integer i= adminMapper.checkIfrtmoney(order);
        return i;
    }

    @Override
    public void delOrder(Order order) {
        adminMapper.delOrder(order);
    }

    @Override
    public Goods getGoodsDetails(Integer gid) {
      Goods goods=adminMapper.getGoodsDetails(gid);
        return goods;
    }

    @Override
    public Integer addShopping(Integer uid, Integer gid) {
     Integer i= adminMapper.addShopping(uid,gid);
        return i;
    }

    @Override
    public List<User> getUser(User user, Double num1, Double num2) {
        List<User> userList= adminMapper.getUser(user);
        List<User> userList1=new ArrayList<>();
        for (User user1 : userList) {
            if(num1!=null&&num2!=null) {
                if(user1.getIncome()>=num1&&user1.getIncome()<=num2){
                    userList1.add(user1);
                }
            }
        }
        if(num1!=null&&num2!=null) {
            return userList1;
        }else {return userList;}
    }

    @Override
    public List<User> getUsers() {
        List<User> userList=adminMapper.getUsers();
        return userList;
    }
    public void addIncome(User user){
        Double income = adminMapper.getIncome(user);
        if (income == null) {
            income = 0.0;
        }
        if(user.getRid()==3){
            income=income-0.01*income;
        }else if (user.getRid()==2){
            if(income>=300){
                income=income-0.01*(income-300);
            }
        }
        user.setIncome(income);
        adminMapper.addIncome(user);
    }

    @Override
    public void delUser(int uid) {
        adminMapper.delUser(uid);
    }

    @Override
    public User upUser(int uid) {
        User user=adminMapper.upUser(uid);
        return user;
    }

    @Override
    public void updateUser(User user) {
        adminMapper.updateUser(user);
    }

    @Override
    public void addUser(User user) {
        adminMapper.addUser(user);
    }

    @Override
    public String getAddress(String se3) {
        String address=adminMapper.getAddress(se3);
        return address;
    }

    @Override
    public List<Goodtype> getGoodType() {
        List<Goodtype> goodtypes=adminMapper.getGoodType();
        return goodtypes;
    }

    @Override
    public void addGoodType(Goodtype goodtype) {
        adminMapper.addGoodType(goodtype);
    }

    @Override
    public int getGtName(Goodtype goodtype) {
        Goodtype goodtype1=adminMapper.getGtName(goodtype);
        if(goodtype1!=null){
            return 0;
        }else {
            return 1;
        }
    }

    @Override
    public void delGoodType(Goodtype goodtype) {
        adminMapper.delGoodType(goodtype);
    }

    @Override
    public void updateGoodType(Goodtype goodtype) {
        adminMapper.updateGoodType(goodtype);
    }

    @Override
    public Goodtype upGoodType(int gtid) {
        Goodtype goodtype=adminMapper.upGoodType(gtid);
        return goodtype;
    }

    @Override
    public List<Merchant> getMerchant(Merchant merchant) {
        List<Merchant> merchants=adminMapper.getMerchant(merchant);
        return merchants;
    }

    @Override
    public void addMerchant(Merchant merchant) {
        adminMapper.addMerchant(merchant);
    }


    @Override
    public void upMerchant(Merchant merchant) {
        adminMapper.upMerchant(merchant);
    }

    @Override
    public void delMerchant(Merchant merchant) {
        adminMapper.delMerchant(merchant);
    }


    @Override
    public void upStatus(Goods goods) {
        adminMapper.upstatus(goods);
    }

    @Override
    public void updateStatus(Goods goods) {
        adminMapper.updatestatus(goods);
    }

    @Override
    public void delGoodUser(String uid) {
        adminMapper.delGoodUser(uid);
    }

    @Override
    public List<Glo> getSe1() {
        List<Glo> glo=adminMapper.getSe1();
        return glo;
    }

    @Override
    public List<Glo> getSe2(String se1) {
        List<Glo> glo=adminMapper.getSe2(se1);
        return glo;
    }

    @Override
    public void upRvtime(Orders orders) {
        adminMapper.upRvtime(orders);
    }

    @Override
    public void pay(Orders orders) {
        User user=adminMapper.pay(orders);
        addIncome(user);
    }

    @Override
    public void updateBStatus(int a) {

    }

    @Override
    public void upBStatus(int a) {

    }

    @Override
    public void upBUser(int a) {

    }

//    @Override
//    public void updateBStatus(int[] arr) {
//        adminMapper.updateBStatus(arr);
//    }
//
//    @Override
//    public void upBStatus(int[] arr) {
//        adminMapper.upBStatus(arr);
//    }
//
//    @Override
//    public void upBUser(int[] arr) {
//        adminMapper.upBUser(arr);
//    }

    @Override
    public Integer Ifadd(int gid) {
       Integer i= adminMapper.Ifadd(gid);
        return i;
    }

//    @Override
//    public void updateBUser(int[] arr) {
//        adminMapper.updateBuser(arr);
//    }





}
